import 'package:common/constant/constant.dart';
import 'package:encrypt/encrypt.dart';

class AesUtil{

  static final IV _iv = IV.fromUtf8(Constant.aesIV) ;
  static final Key key = Key.fromUtf8(Constant.aesKey);
  static final Encrypter _aesModeCbcEncode = Encrypter(AES(key,mode: AESMode.cbc));

  ///AES方式加密
  ///src 要加密的字符串
  static String aesEncrypt(String src) {
    final encrypted = _aesModeCbcEncode.encrypt(src, iv: _iv);
    return encrypted.base64;
  }

  ///AES方式解密
  ///src 要解密的字符串
  static String aesDecrypt(String src) {
    final decrypted = _aesModeCbcEncode.decrypt(Encrypted.fromBase64(src), iv: _iv);
    return decrypted;
  }
}